package org.vectrics.common.controller;

import org.vectrics.common.view.Menu;
import org.vectrics.common.view.MenuItemAction;
import java.util.*;
import org.apache.log4j.*;

public class MenuDefinition {
    private static Category log = Category.getInstance(MenuDefinition.class);
    private String id = "";
    private Vector autoMenuActionList = new Vector();
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getId() {
        return(this.id);
    }
    
    public void addAction(MenuItemAction action) {
        log.debug("addAction() called for menu: " + id);
        autoMenuActionList.add(action);
        log.debug("addAction() action count = " + autoMenuActionList.size());
    }
    
    public Menu makeMenu() {
        log.debug("makeAutoMenu() called. For: " + id);
        Menu menu = null;

        menu = new Menu();

        if (log.isDebugEnabled()) {
            log.debug("makeAutoMenu() - number of menuItems = " + autoMenuActionList.size() + "  for menu = " + id);
        }
	
        for (int i = 0; i < this.autoMenuActionList.size(); i++) {
            MenuItemAction action = (MenuItemAction)autoMenuActionList.elementAt(i);
	    if (log.isDebugEnabled()) {
		    log.debug("makeAutoMenu() - Processing action for item: " + action.getId());
	    }
            menu.processAction(action);
        }
        return(menu);

    }
    
    public MenuItemAction addAutoMenuItem(String menuItemId, String parentId, String desc, String link) {
        String id = "" + desc.hashCode();
/*
        Menu item = new Menu();
        item.setDescription(desc);
        item.setId(id);
        item.setLink(link);
        item.setVisible(true);
*/
        MenuItemAction menuItemAction = new MenuItemAction();
        menuItemAction.setId(menuItemId);
        menuItemAction.setParentId(parentId);
        menuItemAction.setVisible(true);
        menuItemAction.setDescription(desc);
        menuItemAction.setLink(link);

        if (log.isDebugEnabled()) {
            log.debug("addAutoMenuItem() - adding menu item: " + menuItemId + "  To menu: " + id);
        }
        
        addAction(menuItemAction);
        return(menuItemAction);
    }
    
} 
